import { HintBtnView } from "../mapUI/HintBtnView";
import { LayerManager } from "../../manager/LayerManager";
import { RightTopLayerLine } from "../../manager/RightTopLayerLine";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { RemainTimeTool } from "../award/RemainTimeTool";
import { Language } from "../../../../extend/language/Language";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GLabel } from "../../../../com/mui/controls/GLabel";
type int = number;
//class LuckAwardsIconBtn
    
    export  class LuckAwardsIconBtn extends HintBtnView
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            buttonMode = true;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            layer = LayerManager.rightTopUILayer;
            this.line = RightTopLayerLine.lineOne;
            this._loadedBtn = ObjCreate.createGLoadedButton(ResFileConst.LuckAwardsMainBtn, 0, 0, 60, 50, this);
            this._timeLabel = ObjCreate.createLabel("", 4, 50, 52, 20, flash.text.TextFormatAlign.CENTER, this, true, GlobalStyle.greenUint);
            return;
        }

        protected onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.LuckAwardsOpen));
            return;
        }

        public setTime(arg1: int): void
        {
            this._time = arg1;
            this.startTimerCount();
            return;
        }

        /* internal  */startTimerCount(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer();
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                this._timer.start();
            }
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            --this._time;
            if (this._time <= 0 && this._timer) 
            {
                this._timeLabel.visible = false;
                this._timer.stop();
                this._timer.dispose();
            }
            else 
            {
                this._timeLabel.htmlText = "<font color=\'#60e71e\'>" + RemainTimeTool.getRemainTimeBySeconds(this._time) + "<font/ >";
            }
            return;
        }

        public setTxt(): void
        {
            if (this._timer) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer = null;
            }
            this._timeLabel.htmlText = "<font color=\'#FF0000\'>" + Language.getString(100013) + "<font/>";
            return;
        }

        public clear(): void
        {
            this._timeLabel.htmlText = "";
            return;
        }

        protected /* var */_loadedBtn: GLoadedButton;

        /* internal */ /* var */_time: int;

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_timeLabel: GLabel;
    }
